import socket
import json

import glob
import os
import sys
import time
import math
try:
    sys.path.append(glob.glob('../carla/dist/carla-*%d.%d-%s.egg' % (
        sys.version_info.major,
        sys.version_info.minor,
        'win-amd64' if os.name == 'nt' else 'linux-x86_64'))[0])
except IndexError:
    pass

import carla 

if __name__ == '__main__':

    # Connect to client
    client = carla.Client('127.0.0.1', 2000)
    client.set_timeout(2.0)

    world = client.get_world()
    current_map = world.get_map()
    actors = world.get_actors()

    car = 0

    for actor in actors:
        if actor.type_id == 'vehicle.charger2020.charger2020':
            car = actor
    
    if car == 0:
        print("Error: cannot found main car!")
        exit

    lightState = car.get_light_state()

    car.set_light_state(lightState.NONE)
    car.set_light_state(lightState.RightBlinker)
    time.sleep(10)
    car.set_light_state(lightState.NONE)
    car.set_light_state(lightState.LeftBlinker)

    # time.sleep(3)
    # car.set_light_state(lightState.NONE)
    # car.set_light_state(lightState.Reverse)

    time.sleep(10)
    car.set_light_state(lightState.NONE)
    car.set_light_state(lightState.Position)
    time.sleep(10)
    car.set_light_state(lightState.NONE)
    car.set_light_state(lightState.Fog)   
    time.sleep(10)
    car.set_light_state(lightState.NONE)
    car.set_light_state(lightState.Brake)
    time.sleep(10)
    car.set_light_state(lightState.NONE)
    car.set_light_state(lightState.LowBeam)
    time.sleep(10)
    car.set_light_state(lightState.NONE)
    car.set_light_state(lightState.HighBeam)
    time.sleep(10)
    car.set_light_state(lightState.NONE)
    # NONE
# Position  位置
# LowBeam   近光
# HighBeam  远光
# Brake     刹车
# RightBlinker  右转
# LeftBlinker   左转
# Reverse   倒车
# Fog       雾灯
# Interior  内部灯